package com.coderly.onlinegallerysharingplatform.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.coderly.onlinegallerysharingplatform.common.convention.errorcode.ErrorCode;
import com.coderly.onlinegallerysharingplatform.common.response.Response;
import com.coderly.onlinegallerysharingplatform.model.dto.req.follow.*;
import com.coderly.onlinegallerysharingplatform.model.dto.resp.follow.FindFansListRespDTO;
import com.coderly.onlinegallerysharingplatform.model.dto.resp.follow.FindFollowingListRespDTO;
import com.coderly.onlinegallerysharingplatform.service.RelationService;
import com.coderly.onlinegallerysharingplatform.toolkit.ExceptionTrowUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/relation")
@Slf4j
public class RelationController {

    @Resource
    private RelationService relationService;

    /**
     * 关注操作
     * @param followUserReqDTO
     * @return
     */
    @PostMapping("/follow")
    public Response<?> follow(@Validated @RequestBody FollowUserReqDTO followUserReqDTO) {
        return relationService.follow(followUserReqDTO);
    }

    /**
     * 获取指定用户的关注列表
     * @param findFollowingListReqDTO
     * @return
     */
    @PostMapping("/list/following/page")
    public Response<Page<FindFollowingListRespDTO>> findFollowingList(@RequestBody FindFollowingListReqDTO findFollowingListReqDTO) {
        ExceptionTrowUtils.throwIf(findFollowingListReqDTO == null, ErrorCode.PARAMS_ERROR);
        return relationService.findFollowingList(findFollowingListReqDTO);
    }

    /**
     * 获取指定用户的粉丝列表
     * @param findFansListReqDTO
     * @return
     */
    @PostMapping("/list/fans/page")
    public Response<Page<FindFansListRespDTO>> findFansList(@RequestBody FindFansListReqDTO findFansListReqDTO) {
        ExceptionTrowUtils.throwIf(findFansListReqDTO == null, ErrorCode.PARAMS_ERROR);
        return relationService.findFansList(findFansListReqDTO);
    }


    /**
     * 取关操作
     * @param unFollowUserReqDTO
     * @return
     */
    @PostMapping("/unfollow")
    public Response<?> unFollow(@Validated @RequestBody UnFollowUserReqDTO unFollowUserReqDTO) {
        return relationService.unFollow(unFollowUserReqDTO);
    }

    /**
     * 判断当前登录用户是否已经关注该用户
     * @param checkLoginUserIsFansReqDTO 该用户
     * @return
     */
    @PostMapping("/checkLoginUserIsFans")
    public Response<?> checkLoginUserIsFans(@Validated @RequestBody CheckLoginUserIsFansReqDTO checkLoginUserIsFansReqDTO) {
        return relationService.checkLoginUserIsFans(checkLoginUserIsFansReqDTO);
    }
}